/**
 * Copyright (c) 2009-2011, chunquedong(YangJiandong)
 * 
 * This file is part of ChunMap project
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
 * 
 * History:
 *     2010-05-05  Jed Young  Creation
 */
package chunmap.model.relate.relateop;

import chunmap.model.geom.Geometry;
import chunmap.model.geom.Ring;
import chunmap.model.geom.Polygon;
import chunmap.model.relate.ComputeIm;
import static chunmap.model.relate.IntersectionMatrix.*;

/**
 * @author chunquedong
 * 
 */
class LinearRing_LinearRing extends ComputeIm {

	public LinearRing_LinearRing(Ring r1, Ring r2) {
		g1 = r1.toPolygon();
		g2 = r2.toPolygon();
	}

	@Override
	protected int inner2innerDim(Geometry g1, Geometry g2) {

		if (im.get(Inner, Border) != EmptyDim)
			return AreaDim;
		if (im.get(Border, Inner) != EmptyDim)
			return AreaDim;

		if (im.get(Border, Outer) == EmptyDim)
			return AreaDim;
		if (im.get(Outer, Border) == EmptyDim)
			return AreaDim;

		return EmptyDim;
	}

	@Override
	protected boolean within(Geometry g1, Geometry g2) {
		Ring r1 = ((Polygon) g1).getShell();
		Ring r2 = ((Polygon) g2).getShell();
		if (r2.containLineStringIn(r1))
			return true;
		else
			return false;
	}

}